package com.tbs.parkingsaleapp.UI.LoginOrSign.Base;

import abstergo.tbs.betterasyc.AsycBase.AsycWorker;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.tbs.parkingsaleapp.Http.JsonData.LoginResult;
import com.tbs.parkingsaleapp.Http.Listenner.CommonLoginHttper;
import com.tbs.parkingsaleapp.R;
public class CommonLoginFragment extends Fragment implements View.OnClickListener {
    public CommonLoginFragment() {
        // Required empty public constructor
    }
    Button btn;
    EditText username,password;
    Switch isrem;
    public boolean IsRemember()
    {
        return isrem.isChecked();
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View main=inflater.inflate(R.layout.fragment_common_login, container, false);
        btn=main.findViewById(R.id.comloginbtn);
        username=main.findViewById(R.id.userusername);
        password=main.findViewById(R.id.userpassword);
        isrem= main.findViewById(R.id.remlogin);
        btn.setOnClickListener(this);
        return main;
    }

    @Override
    public void onClick(View view) {
        if(username.getText().length()==0)
        {
            Toast.makeText(getContext(), "请输入用户名", Toast.LENGTH_SHORT).show();
            return;
        }

        if(password.getText().length()==0)
        {
            Toast.makeText(getContext(), "请输入密码", Toast.LENGTH_SHORT).show();
            return;
        }
        AsycWorker<String, LoginResult> login=new AsycWorker<>(1);
        CommonLoginHttper httper=new CommonLoginHttper(this);
        httper.Show();
        login.setBackgroundAction(httper).setContext(getContext());
        login.setResultAction(httper);
        login.Run(username.getText().toString(),password.getText().toString());
    }
}